package com.haibei.adapter.bean;

import android.app.Activity;
import android.view.View;
import android.widget.TextView;

import com.common.bean.IBeanInterface;
import com.haibei.R;
import com.haibei.activity.MainActivity;
import com.haibei.view.AsnycImageView;

public class GoodsTypeItem implements IBeanInterface {

	private GoodsType goodsType;
	private MainActivity mActivity;
	private View contentView;

	private AsnycImageView imageViewIcon;
	private TextView mTextViewTitle;

	public GoodsTypeItem(Activity activity, GoodsType goodsType) {
		this.goodsType = goodsType;
		this.mActivity = (MainActivity) activity;
		contentView = View.inflate(activity, R.layout.item_view_goods_type, null);
		imageViewIcon = (AsnycImageView) contentView.findViewById(R.id.imageViewIcon);
		imageViewIcon.setmDefaultDrable(activity.getResources().getDrawable(R.drawable.icon_health));
		mTextViewTitle = (TextView) contentView.findViewById(R.id.textViewIdTypeName);
		mTextViewTitle.setText(goodsType.getName());
		unCheck();
	}

	public void check() {
		if (goodsType.isDefault()) {
			imageViewIcon.setmDefaultDrable(mActivity.getResources().getDrawable(goodsType.getIconSelected()));
			mActivity.showContent();
		} else {
			String url = goodsType.getIconSelectUrl();
			imageViewIcon.setUrl(url);
		}
		mTextViewTitle.setTextColor(mActivity.getResources().getColor(R.color.text_color_green));
	}

	public void unCheck() {
		if (goodsType.isDefault()) {
			imageViewIcon.setmDefaultDrable(mActivity.getResources().getDrawable(goodsType.getIconDefault()));
			imageViewIcon.invalidate();
		} else {
			String url = goodsType.getIconDefaultUrl();
			imageViewIcon.setUrl(url);
		}
		mTextViewTitle.setTextColor(mActivity.getResources().getColor(R.color.text_color_dark));
	}

	public View getView() {
		contentView.setTag(this);
		return contentView;
	}

	public GoodsType getGoodsType() {
		return goodsType;
	}

	public void setGoodsType(GoodsType goodsType) {
		this.goodsType = goodsType;
	}

}
